package hu.codelab.lg.servicecenter.adapters;

import hu.codelab.lg.servicecenter.R;
import hu.codelab.lg.servicecenter.entities.Phone;

import java.util.List;

import android.app.Activity;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PhonesAdapter extends BaseAdapter {

    protected final Activity activity;

    private final List<Phone> phones;
    private final Typeface font;

    public PhonesAdapter(final Activity activity, final List<Phone> phones) {
        this.activity = activity;
        this.phones = phones;

        font = Typeface.createFromAsset(activity.getAssets(), "helvetica_neue.ttf");
    }

    @Override
    public int getCount() {
        return phones.size();
    }

    @Override
    public Object getItem(final int position) {
        return phones.get(position);
    }

    @Override
    public long getItemId(final int position) {
        return 0;
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
        TextView view = (TextView) convertView;

        if (view == null) {
            view = new TextView(activity.getBaseContext());
            view.setPadding(5, 25, 5, 25);
            view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
            view.setTypeface(font);
            view.setTextSize(18);
            view.setTextColor(activity.getResources().getColor(R.color.lg_gray));
        }

        final Phone phone = phones.get(position);

        view.setText(phone.getNumber());

        return view;
    }

}
